package org.emet.entity.ash;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.emet.jee.console.entity.BaseEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 架
 * 
 * @author alex
 * 
 */
@Entity
@Table(name = "t_frame")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Frame extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String code;
	private String name;
	private AshHall ashHall;
	private List<AshItem> items;
	// private List<AshItemRow> itemRows;
	private int maxRow;
	private int maxCol;

	@Column(nullable = false, unique = true)
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToOne
	@JoinColumn(name = "hall_id")
	public AshHall getAshHall() {
		return ashHall;
	}

	public void setAshHall(AshHall ashHall) {
		this.ashHall = ashHall;
	}

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "frame")
	@OrderBy("row,col")
	public List<AshItem> getItems() {
		return items;
	}

	public void setItems(List<AshItem> items) {
		this.items = items;
	}



	public int getMaxRow() {
		return maxRow;
	}

	public void setMaxRow(int maxRow) {
		this.maxRow = maxRow;
	}

	public int getMaxCol() {
		return maxCol;
	}

	public void setMaxCol(int maxCol) {
		this.maxCol = maxCol;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 0;
		result = prime * result + ((code == null) ? 0 : code.hashCode());
		result = prime * result + ((ashHall == null) ? 0 : ashHall.hashCode());
		result = prime * result + ((items == null) ? 0 : items.hashCode());
		result = prime * result + maxCol;
		result = prime * result + maxRow;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (getClass() != obj.getClass())
			return false;
		Frame other = (Frame) obj;
		if (code == null) {
			if (other.code != null)
				return false;
		} else if (!code.equals(other.code))
			return false;
		if (ashHall == null) {
			if (other.ashHall != null)
				return false;
		} else if (!ashHall.equals(other.ashHall))
			return false;
		if (items == null) {
			if (other.items != null)
				return false;
		} else if (!items.equals(other.items))
			return false;
		if (maxCol != other.maxCol)
			return false;
		if (maxRow != other.maxRow)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

}
